#ifndef _COMMON_H_
#define _COMMON_H_

// platform
#if defined(_WIN32)
#   define MCL_WIN
#elif defined(TARGET_OS_IPHONE) || defined(TARGET_OS_IPAD)
#   define MCL_APPLE
#elif defined(__ANDROID__)
#   define MCL_ANDROID
#else
#   define MCL_LINUX
#endif

#if defined (_DEBUG)
#   define MCL_DEBUG
#endif

// includes
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>

#if defined(MCL_WIN)
#   include <WinSock2.h>
#   include <malloc.h>
#   include <direct.h>

#elif defined(MCL_APPLE)
#   include <unistd.h>
#   include <sys/socket.h>
#   include <sys/stat.h>
#   include <sys/types.h>
#   include <netinet/in.h>
#   include <netdb.h>
#   include <malloc/malloc.h>
#   include <poll.h>

#elif defined(MCL_ANDROID)
#   include <unistd.h>
#   include <sys/socket.h>
#   include <sys/stat.h>
#   include <sys/types.h>
#   include <netinet/in.h>
#   include <netdb.h>
#   include <malloc.h>
#   include <poll.h>

#elif defined(MCL_LINUX)
#   include <unistd.h>
#   include <sys/socket.h>
#   include <sys/stat.h>
#   include <sys/types.h>
#   include <netinet/in.h>
#   include <netdb.h>
#   include <malloc.h>
#   include <poll.h>

#endif

// integer types
typedef int8_t  int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;

typedef uint8_t  uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;

#if defined(MCL_WIN)
typedef SOCKET      HSOCKET;
typedef int         SOCKLEN_T;
//#define INVALID_SOCKET  INVALID_HANDLE_VALUE

#else
typedef int         HSOCKET;
typedef socklen_t   SOCKLEN_T;
#define INVALID_SOCKET  -1

#endif

// crt fucking stuffs
#if defined(MCL_WIN)

#   define strdup   _strdup
#   define snprintf _snprintf
#   define stricmp  _stricmp

#else// non win

#   define stricmp  strcasecmp

#endif

#include "MCL_Macros.h"

#endif
